package com.lmh.ymw.service.product;

import com.lmh.ymw.entity.Product;
import com.lmh.ymw.mapper.product.ProductDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    ProductDao dao;
    @Override
    public boolean add(Product product) {
        int i = dao.insertSelective(product);
        if (i != 0) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean update(Product product) {
        int i = dao.updateByPrimaryKeySelective(product);
        if (i != 0) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean deleteProductById(Integer productId) {
        int i = dao.deleteByPrimaryKey(productId);
        if (i != 0) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    public  List<Product> getProductByIdList(Integer productId) {
        List<Product> products = dao.selectProduct(productId);
        return products;
    }

    @Override
    public Product getProductById(Integer productId) {
        Product product = dao.selectByPrimaryKey(productId);

        return product;
    }

    @Override
    public List<Product> getProductList() {
        return dao.selectAll();
    }
}
